import axios from 'axios'
import { Modal } from 'antd-mobile';
const alert = Modal.alert;
// const devUrl = '/api';
// const prodUrl = 'https://shadow.elemecdn.comp';
// const apiUrl = devUrl;

const service = axios.create({
    // baseURL: apiUrl,
    timeout: 10000,
})
// 请求拦截
service.interceptors.request.use(
    config => {
        // if (window.sessionStorage.getItem("token")) {
        //   config.headers['Authorization'] = window.sessionStorage.getItem("token")
        // }
        return config
    },
    error => {
        return Promise.reject(error)
    }
)
// 响应拦截
service.interceptors.response.use(
    response => {
        const res = response.data
        // if (res.code !== 0) {
        //   return Promise.reject(new Error(res.message || 'Error'))
        // } else {
        //   return res
        // }
        return res
    },
    error => {
        if (JSON.stringify(error).includes("time")) {
            alert('网络超时', '请重试!', [
                { text: '取消', onPress: () => console.log('cancel') },
                { text: '确定', onPress: () => window.location.reload() },
            ])
        }
        return Promise.reject(error)
    }
)
export default service